package org.smartboot.flow.springboot.extension;

import org.smartboot.flow.manager.report.HttpReporter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * smart flow httReport auto config
 *
 * @author huqiang
 * @since 2022/12/15 16:32
 */
@Configuration
@ConfigurationProperties(prefix = "smart.flow.report.http")
@ConditionalOnProperty(name = "smart.flow.report.http.url")
public class FlowHttpReportConfiguration {

    /**
     * Connect timeout in microseconds.
     */
    private long timeout;

    /**
     * Report url.
     */
    private String url;

    /**
     * Default idle in microseconds.
     */
    private long idle = 5000L;

    @Bean(value = "smart-flow-http-reporter", initMethod = "start")
    public HttpReporter getHttpReporter() {
        HttpReporter reporter = new HttpReporter();
        reporter.setTimeout(this.timeout);
        reporter.setUrl(this.url);
        reporter.setIdle(this.idle);
        return reporter;
    }

    public void setTimeout(long timeout) {
        this.timeout = timeout;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void setIdle(long idle) {
        this.idle = idle;
    }
}
